package zkk.com.mengqu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import zkk.com.mengqu.R;
import zkk.com.mengqu.models.Food;

/**
 * Created by Administrator on 2017/5/20.
 * 提交订单设配器
 */
public class SubmitOrderAdapter extends BaseAdapter {
    private Context context;
    private List<Food> foodList;

    public SubmitOrderAdapter(Context context,List<Food> foodList){
        this.context = context;
        this.foodList = foodList;
    }

    @Override
    public int getCount() {
        return foodList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.item_submit_order,null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder)convertView.getTag();
        }

        holder.name.setText("" + foodList.get(position).getName());
        holder.allPrice.setText("" + foodList.get(position).getPrice() * foodList.get(position).getCount());
        holder.num.setText("" + foodList.get(position).getCount());

        return convertView;
    }

    class ViewHolder{
        private TextView name;//商品名字
        private TextView allPrice;//商品价格
        private TextView num;//商品数量

        public ViewHolder(View view){
            name = (TextView) view.findViewById(R.id.tx_food_name);
            allPrice = (TextView) view.findViewById(R.id.tx_food_price);
            num = (TextView) view.findViewById(R.id.tx_food_count);
        }
    }
}
